<!DOCTYPE html>
<html lang="en">
<title>编辑轮播</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="banner-add-box col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>编辑轮播</h5>
            </div>
            <div class="ibox-content">
                <form method="post" id="uploadForm" name="fileinfo" class="form-horizontal" enctype="multipart/form-data">
                    <div class="form-group"><label class="col-sm-2 control-label">标题</label>
                        <input type="hidden" name="id" value="${elements.id}">
                        <div class="col-sm-10"><input type="text" name="title" value="${elements.title}" id="title" class="form-control"></div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label">链接</label>
                        <div class="col-sm-10"><input type="url" name="previewUrl" value="${elements.link}" id="previewUrl" class="form-control"></div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label">轮播图</label>
                        <div class="col-sm-10">
                            <label for="file" class="file-input">
                                <input type="file" src="${elements.url}" name="file" id="file"/>
                                <img alt="" width="100px" src="${elements.url}">
                                <svg width="20" height="20" viewBox="0 0 20 17">
                                    <path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/>
                                </svg>
                                <span>选择文件 ...</span>
                            </label>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-12">
                            <button type="button" id="goBack" class="btn btn-default pull-left">取消修改</button>
                            <button type="button" id="add_operating" class="btn btn-success pull-right">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function () {
        $("#add_operating").click(function () {
            doUpload();
        });
        $("#goBack").click(function () {
            window.location.href = 'to_operating_manage';
        });
    });

    function doUpload() {
        var title = Trim($("#title").val(), 'g');
        var previewUrl = Trim($("#previewUrl").val(), 'g');
        if (title == '') {
            swal("标题不能为空!", '', 'error');
            $("#title").focus();
            return;
        }
        if (previewUrl == '') {
            swal("链接不能为空!", '', 'error');
            $("#previewUrl").focus();
            return;
        }
        var url = 'operating_edit';
        var formData = new FormData($("#uploadForm")[0]);

        swal({
            title: '修改确认',
            text: "",
            type: 'question',
            showCancelButton: true,
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, 确认修改',
            cancelButtonText: 'No, 再次确认',
        }).then(function () {
            $.ajax({
                url: url,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    if (returndata > 0) {
                        swal("修改成功!", "页面即将跳转,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.href = 'to_operating_manage?1=1#tab-3';
                        }, 1000)
                    }
                },
                error: function (returndata) {
                    swal(returndata, '', 'error');
                }
            });
        }, function () {
        });
    }


    function Trim(str, is_global) {
        var result;
        result = str.replace(/(^\s+)|(\s+$)/g, "");
        if (is_global.toLowerCase() == "g")
            result = result.replace(/\s/g, "");
        return result;
    }
</script>

</@body.page>
</html>